<c:if test="true" xmlns:f="http://java.sun.com/jsf/core"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:nxu="http://nuxeo.org/nxweb/util"
  xmlns:nxp="http://nuxeo.org/nxweb/pdf"
  xmlns:nxd="http://nuxeo.org/nxweb/document"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:rich="http://richfaces.org/rich">
  <c:if test="#{nxl:isLikePlainMode(widget.mode)}">
    <nxu:inputList value="#{fieldOrValue}" model="model"
      rendered="#{not empty field}">
      <nxu:set var="canSee"
        value="#{docSuggestionActions.getDocumentExistsAndIsVisibleWithId(model.rowData)}">
        <h:panelGroup rendered="#{canSee}">
          <nxu:set var="doc"
            value="#{docSuggestionActions.getDocumentWithId(model.rowData)}">
            <h:outputText value="#{nxd:titleOrId(doc)}" />
          </nxu:set>
        </h:panelGroup>
        <h:panelGroup rendered="#{not canSee}">
          <h:outputText
            value="#{messages['label.documentSuggestion.docNotFoundOrNotVisible']} (#{model.rowData})" />
        </h:panelGroup>
        <h:outputText value=", "
          rendered="#{model.rowIndex != (model.rowCount-1)}" />
      </nxu:set>
    </nxu:inputList>
  </c:if>
  <c:if test="#{widget.mode == 'pdf'}">
    <nxp:html>
    <h:dataTable value="#{field}" var="docid"
      rendered="#{not empty field}">
      <h:column>
        <nxu:set var="canSee"
          value="#{docSuggestionActions.getDocumentExistsAndIsVisibleWithId(docid)}">
          <h:panelGroup rendered="#{canSee}">
            <nxu:set var="doc"
              value="#{docSuggestionActions.getDocumentWithId(docid)}">
              <nxu:graphicImage value="#{nxd:iconPath(doc)}"
                rendered="#{!empty nxd:iconPath(doc)}" />
              <h:outputText value=" #{nxd:titleOrId(doc)} " />
            </nxu:set>
          </h:panelGroup>
          <h:panelGroup rendered="#{not canSee}">
            <h:outputText
              value="#{messages['label.documentSuggestion.docNotFoundOrNotVisible']} (#{docid})" />
          </h:panelGroup>
        </nxu:set>
      </h:column>
    </h:dataTable>
    </nxp:html>
  </c:if>
  <c:if test="#{nxl:isLikeViewMode(widget.mode)}">

    <h:dataTable value="#{field}" var="docid"
      rendered="#{not empty field}">
      <h:column>
        <nxu:set var="canSee"
          value="#{docSuggestionActions.getDocumentExistsAndIsVisibleWithId(docid)}">
          <h:panelGroup rendered="#{canSee}">
            <nxu:set var="doc"
              value="#{docSuggestionActions.getDocumentWithId(docid)}">
              <nxu:graphicImage value="#{nxd:iconPath(doc)}"
                rendered="#{!empty nxd:iconPath(doc)}"
                style="vertical-align:middle" styleClass="smallIcon" />
              <h:outputText value=" #{nxd:titleOrId(doc)} " />
              <nxd:restDocumentLink document="#{doc}"
                newConversation="true" target="_blank"
                tab="#{widgetProperty_tab}"
                subTab="#{widgetProperty_subTab}">
                <nxu:graphicImage value="/icons/external.gif"
                  style="vertical-align:middle"
                  alt="#{messages['permalink.newTab']}"
                  title="#{messages['permalink.newTab']}" />
              </nxd:restDocumentLink>
            </nxu:set>
          </h:panelGroup>
          <h:panelGroup rendered="#{not canSee}">
            <h:outputText
              value="#{messages['label.documentSuggestion.docNotFoundOrNotVisible']} (#{docid})" />
          </h:panelGroup>
        </nxu:set>
      </h:column>
    </h:dataTable>

  </c:if>
  <c:if test="#{widget.mode == 'edit'}">

    <nxu:set var="helpLabel"
    value="#{nxu:test(empty widgetProperty_helpLabel, messages['label.suggestion.help.minChars'], nxu:test(widget.translated, messages[widgetProperty_helpLabel], widgetProperty_helpLabel))}"
    cache="true">

    <ui:include src="/incl/select2_js.xhtml" />

    <a4j:region>
      <nxu:valueHolder id="#{widget.id}_select2" value="#{field_0}"
        required="#{widgetProperty_required}" var="currentValue">
        <f:converter converterId="select2Converter" />
        <f:attribute name="separator" value="#{widgetProperty_separator}" />
        <nxu:validateDocumentConstraint />
        <h:inputHidden readonly="true" id="#{widget.id}_select2_init"
          value="#{select2Actions.resolveMultipleReferences(currentValue, widgetProperty_repository,widgetProperty_initOperationId, widgetProperty_idProperty, widgetProperty_documentSchemas)}" />
      </nxu:valueHolder>

      <c:if test="#{not empty widgetProperty_ajaxReRender}">
        <a4j:jsFunction name="#{widget.id}_reRender"
          render="#{widgetProperty_ajaxReRender}" />
      </c:if>

    </a4j:region>

    <c:if
      test="#{widget.mode == 'edit' and !widgetProperty_hideHelpLabel}">
      <p class="detail">
        <h:outputFormat value="#{helpLabel}">
          <f:param value="#{widgetProperty_minChars}" />
        </h:outputFormat>
      </p>
    </c:if>

    <h:inputHidden readonly="true" id="#{widget.id}_select2_params"
      value="#{select2Actions.encodeParameters(widget, widgetProperties)}" />
    <h:message for="#{widget.id}_select2" styleClass="errorMessage" />

    </nxu:set>

  </c:if>
</c:if>
